package com.fengchao.util.common;

import net.sourceforge.pinyin4j.PinyinHelper;

/**
 * Created by http://my.oschina.net/wangnian on 2016/9/12.
 */
public class PinyinTools {

    /**
     * 提取每个汉字的首字母
     *
     * @param str
     * @return String
     */
    public static String getPinYinHeadChar(String str) {
        String convert = "";
        char word = str.charAt(0);
        String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
        if (pinyinArray != null) {
            convert += pinyinArray[0].charAt(0);
        } else {
            convert += word;
        }
        return convert;
    }
}
